<template>
    <div>
        <h1>房型添加</h1>
<table class="table table-bordered" border="1">
    <tr>
        <td>房型名称</td>
        <td><input type="text" v-model="ad.rType_name"></td>
    </tr>

    <tr>
        <td>门市价</td>
        <td><input type="text" v-model="ad.rType_price"></td>
    </tr>

    <tr>
        <td>押金</td>
        <td><input type="text"  v-model="ad.rType_deposit"></td>
    </tr>

    <tr>
        <td>面积</td>
        <td><input type="text" v-model="ad.rType_size"></td>
    </tr>

    <tr>
        <td>可住人数</td>
        <td><input type="text" v-model="ad.rType_num"></td>
    </tr>

    <tr>
        <td>是否加床</td>
        <td><select v-model="ad.rType_Addbed">
            <option  value="">请选择</option>
            <option  value="1">是</option>
            <option  value="2">否</option>
        </select></td>
    </tr>

    <tr>
        <td>房型图片</td>
        <td><img style="right: 80px; height: 80px;" :src="ad.rType_img">
        <input type="file" @change="show"></td>
    </tr>

    <tr>
        <td>房型介绍</td>
        <td><input type="text" v-model="ad.rType_info"></td>
    </tr>


    <tr>
        <td>房型投放</td>
        <td><input type="text" v-model="ad.rType_state"></td>
    </tr>


    <tr>
        <td></td>
        <td><input type="button" value="注册" @click="pdadd"></td>
    </tr>
</table>
    </div>
</template>

<script setup lang="ts">
import { ref ,onMounted} from "vue";
import axios from "axios";
import { useRoute } from "vue-router";

const Route=useRoute();
const file =ref(null)


onMounted(()=>{

    ft();
})
const show=(tpid:any)=>{

   file.value=tpid.target.files[0];

if(!file.value)
{

alert('请选择上传图片');
return;
}


const data= new FormData();

data.append("imge",file.value);
axios.post('https://localhost:7268/api/wjsc/fileupload',data)
.then(res=>{

    if(res.data.fileconm_cod==0)
{
alert(res.data.fileconm_msg)
}

else if(res.data.fileconm_cod==1)
{
alert(res.data.fileconm_msg)
}
else{
    console.log(res.data)
    ad.value.rType_img=res.data.fileconm_Path;


}
   
})
.catch(error=>{

    console.log(error);
});

}





const ad=ref({

    rType_id: 0,
  rType_name: "",
  rType_price: 0,
  rType_deposit: 0,
  rType_size: 0,
  rType_num: 0,
  rType_Addbed: "",
  rType_img: "",
  rType_info: "",
  rType_state: "",
  rType_infd: false,
  datet: "2024-10-31T03:21:51.229Z"
})

const pdadd=()=>{
axios.put('https://localhost:7268/api/fx/xglist',ad.value)
.then(res=>{

if(res.data>0)
{
alert('修改成功');
location.href="/fxxs"
}
else{

alert('修改失败');

}

})
.catch(error=>{

    console.log(error);
})





}

const ft=()=>{

    axios.get('https://localhost:7268/api/fx/ftlist',{

     params:{

        rType_id:Route.params.id
     }

    })
.then(res=>{


    ad.value=res.data
})

}

</script>

<style scoped>

</style>